package com.acme.bankapp.domain;


import java.util.List;

import com.acme.bankapp.domain.Client;

/**
 * Domain bank
 *
 */
public class Bank {
	
	/**
	 * clients
	 */
	private List<Client> clients;	
	private List<ClientRegistrationListener> clientRegistrationListeners;
	
	Bank(List<ClientRegistrationListener> clientRegistrationListeners, List<Client> clients){
		this.clientRegistrationListeners = clientRegistrationListeners;	
		this.clients = clients;
	}
	

	/**
	 * Get list of banks clients
	 * @return list of clients
	 */
	public List<Client> getClients(){
		return clients;
	}
	
	void addClient(Client client) throws ClientExistsException{
		if(clients.contains(client)) throw new ClientExistsException(client.getClientSalutation());

		clients.add(client);
		for(ClientRegistrationListener listener : clientRegistrationListeners){
			if(listener!=null){
				listener.onClientRegistred(client);
			}
		}
	}
	
	
	public interface ClientRegistrationListener {
		void onClientRegistred(Client client);
	}
	

}
